﻿/*
 
Celerity: Sensory Overload
Copright 2012 by Adam Hill, David Gannon, Thomas Tamblyn & Patrick Ytting
Contact: adam.hill@outlook.com
Website: adamhill.org
Licence: MS-Pl Licence
  
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Celerity.Util
{
    public static class StatisticsUtil
    {
        static double[] FrameTimes = new double[6] { 0, 0, 0, 0, 0, 0 };
        public static int FrameTimePointer = 0;

        /// <summary>
        /// Computes the average frame time in seconds based on the last five frame times.
        /// </summary>
        public static double FrameTime { get { return FrameTimes.Average() / 1000.0f; } }

        /// <summary>
        /// Computes frames per second based on the last five frame times.
        /// </summary>
        public static double FPS { get { return 1.0 / FrameTime; } }        

        /// <summary>
        /// Add the latest frame time to the list.
        /// </summary>
        /// <param name="time">
        /// Frame time in milliseconds.
        /// </param>
        public static void Update(double time)
        {
            FrameTimes[FrameTimePointer] = time;
            FrameTimePointer++;
            if (FrameTimePointer > FrameTimes.GetUpperBound(0))
            {
                FrameTimePointer = 0;
            }
        }

    }
}
